<?php 

require_once ($_SERVER['DOCUMENT_ROOT'].'/../application/configs/settings.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/../application/models/mysqlConnect.php');

require_once ($_SERVER['DOCUMENT_ROOT'].'/../application/models/users/usersDb.php');

echo "<pre>Post:";
print_r($_POST);
echo "</pre>";

echo "<pre>Get:";
print_r($_GET);
echo "</pre>";

echo "<pre>Files:";
print_r($_FILES);
echo "</pre>";

if(isset($_GET['action']))
	$action=$_GET['action'];
else
	$action='select';

$data=array(
	'name'=>'',
	'email'=>'',
	'phone'=>'',
	'address'=>'',
	'city'=>'Santiago',
	'postalcode'=>'15000',
	'gender'=>'',
	'description'=>'',
	'provinces_id'=>'1',
	'likes'=>array(),
	'languages'=>array()
);
switch($action)
{
	case 'update':
		if($_POST)
		{
			updateUser($_POST,$_FILES,$privateKey,$database);
			header('Location: /usersdb.php');
			break;
		}			
		else 
			$data=getUser($_GET['id'],$database);		
	case 'insert':	
		if($_POST)
		{
			$id=insertUser($_POST,$_FILES,$privateKey,$database);
			header('Location: /usersdb.php');
		}			
		else 
			include ($_SERVER['DOCUMENT_ROOT']."/../application/views/scripts/users/insert.php");
	break;
	case 'delete':
		if($_POST)
		{
			if(isset($_POST['delete']))
				deleteUser($_POST,$database);
			header('Location: /usersdb.php');
		}			
		else
		{
			$data=getUser($_GET['id'],$database);
			include ($_SERVER['DOCUMENT_ROOT']."/../application/views/scripts/users/delete.php");
		}
			
	break;
	case 'select':
	default:
		$arrayUsers=getUsers($database);			
		include_once ($_SERVER['DOCUMENT_ROOT'].'/../application/views/scripts/users/select.php');
		
	break;
}

